import doctest

class Context:
    REGISTER_COUNT = 4
    MIN_REGISTER_INDEX = 128
    MAX_REGISTER_INDEX = MIN_REGISTER_INDEX + REGISTER_COUNT - 1
    REGISTER_COMPARE_INDEX = REGISTER_COUNT - 1

    def __init__(self):
        self.__registers = [0] * Context.REGISTER_COUNT
        self.__offset = 0
        
    @staticmethod
    def from_data(data):
        '''
        >>> context = Context.from_data([1, 2, 3])
        >>> context.getregisters()[:3]
        (1, 2, 3)
        '''
        context = Context()
        for i in range(len(data)):
            context.__registers[i] = data[i]
        return context
        
    def getregister(self, index):
        return self.__registers[index]
    
    def setregister(self, index, value):
        self.__registers[index] = value % 256
        
    def getregisters(self):
        return tuple(self.__registers)
    
    def setregisters(self, values):
        for i in range(len(values)):
            self.__registers[i] = values[i]
    
    def getcmpregister(self):
        return self.__registers[Context.REGISTER_COMPARE_INDEX]
    
    def setcmpregister(self, value):
        self.__registers[Context.REGISTER_COMPARE_INDEX] = value
        
    def getoffset(self):
        return self.__offset
    
    def setoffset(self, offset):
        self.__offset = offset
        
    def nextoffset(self):
        '''
        >>> context = Context()
        >>> context.setoffset(3)
        >>> context.getoffset()
        3
        >>> context.nextoffset()
        3
        >>> context.getoffset()
        4
        '''
        next = self.__offset
        self.__offset += 1
        return next
            
if __name__ == '__main__':
    doctest.testmod()